package com.sinosoft.flow.config;

import com.sinosoft.flow.config.constant.ResponseCode;

/**
 * @Author: tangyongbo
 * @Description:
 * @Date: create in 2021/11/9 16:34
 */
public class ResponseWrapper<T> {
    private Integer code;
    private String message;
    private T data;

    public ResponseWrapper(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public ResponseWrapper() {
    }

    public ResponseWrapper(ResponseCode responseCode) {
        this.code=responseCode.getCode();
        this.message=responseCode.getMessage();
    }
    public ResponseWrapper(ResponseCode responseCode,T data) {
        this.code=responseCode.getCode();
        this.message=responseCode.getMessage();
        this.data=data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static ResponseWrapper ok(){
        return new ResponseWrapper(ResponseCode.SUCCESS);
    }

    public static <T> ResponseWrapper<T> ok(T data){
        return new ResponseWrapper(ResponseCode.SUCCESS,data);
    }

    public static ResponseWrapper fail(){
        return new ResponseWrapper(ResponseCode.INTERNAL_SERVER_ERROR);
    }

    public static ResponseWrapper fail(ResponseCode responseCode){
        return new ResponseWrapper(responseCode);
    }
}
